/*
******************************************************************************************************* 
**  Copyright (C) 2019, 苏州检易生物科技有限公司 
**  All rights reserved. 
** 
**  FileName:       	pmt.h
**  Description:	
**  Author:        	 
**  Version				v0.1
**  Date:           	2019-05-24
**	Function List： 
**  History:         
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                              	防止重复包含
*********************************************************************************************************
*/

#ifndef  _CLAW485_H_
#define  _CLAW485_H_
/*
*********************************************************************************************************
*                                              	调试开关
*********************************************************************************************************
*/
#include "log_console.h"
#include "modbus.h"
#include "bsp_conf.h"


/*
*********************************************************************************************************
*                                              	宏定义
*********************************************************************************************************
*/
//测试时间
#define CLAW485_BAUDRATE	115200
/*
*********************************************************************************************************
*                                              枚举和结构体类型定义
*********************************************************************************************************
*/


typedef enum claw_reg{
	REG_SAVE	=	25,
	REG_ADDR	=	31,
	REG_CONTROL_MODE	=	53,
	REG_OPEN	=	54,
	REG_CLOSE	=	55,
	REG_OPEN_POS_LOW = 56,
	REG_OPEN_POS_HIGH = 57,
	REG_CLOSE_POS_LOW = 58,
	REG_CLOSE_POS_HIGH = 59,
	REG_STATUS	=	64,
	REG_CURRENT	=	65,
}claw_reg_t;

typedef enum{
	REG_STATUS_CATCHED	= 1,
	REG_STATUS_CLOSED	= 2,
	REG_STATUS_CLOSING	= 4,
	REG_STATUS_OPENING	= 5,
	REG_STATUS_OPENED	= 6,
	REG_STATUS_IDLE	= 0,
	REG_STATUS_ERR	= 15,
}reg_status_t;


typedef struct CLAW{
//	bsp_uart_t * p_uart;
	modbus_t * p_modbus;
	
	uint8_t address;
	reg_status_t status;
	
	uint8_t poll_tick; /*轮询的时间计数*/
//	void	(*pfn_status_cb)(struct CLAW * handle,reg_status_t status);
}claw_t;

//typedef void (*pmt_rlt_callback)(pmt_t* handle,uint32_t rlt);
/*
*********************************************************************************************************
*                                              	全局变量声明
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                              	函数声明
*********************************************************************************************************
*/
claw_t* claw_init(modbus_t* p_modbus,uint8_t address);
reg_status_t claw_open(claw_t* p_claw);
reg_status_t claw_change_address(claw_t* p_claw,uint8_t new_address);
reg_status_t claw_close(claw_t* p_claw);
reg_status_t claw_status(claw_t* p_claw);
#endif
